from django.contrib import admin
from .models import Category, TodoItem


@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    list_display = ['name', 'color', 'created_at']
    search_fields = ['name']
    list_filter = ['created_at']


@admin.register(TodoItem)
class TodoItemAdmin(admin.ModelAdmin):
    list_display = ['title', 'category', 'priority', 'due_date', 'is_completed', 'created_at']
    list_filter = ['category', 'priority', 'is_completed', 'created_at']
    search_fields = ['title', 'description']
    date_hierarchy = 'created_at'
    list_editable = ['is_completed']
    readonly_fields = ['created_at', 'updated_at', 'completed_at']
    
    fieldsets = (
        ('基本信息', {
            'fields': ('title', 'description', 'category')
        }),
        ('优先级和时间', {
            'fields': ('priority', 'due_date', 'is_completed')
        }),
        ('时间戳', {
            'fields': ('created_at', 'updated_at', 'completed_at'),
            'classes': ('collapse',)
        }),
    )
